package com.gohi.main.system.action;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;

import com.gohi.core.web.action.BaseAction;
import com.gohi.main.store.service.IStoreService;
import com.gohi.main.system.hbm.ShopgooArea;
import com.gohi.main.system.service.ISystemService;
import com.gohi.main.user.hbm.ShopgooMember;
import com.gohi.main.user.hbm.ShopgooMessage;
import com.gohi.main.user.service.IUserService;
import com.gohi.main.util.AppJsonUtils;
import com.gohi.main.util.Utils;
import com.gohi.main.util.global.GloblConfig;

import com.gohi.main.wxapi.process.MsgXmlUtil;
import com.gohi.main.wxapi.util.AccoutUtil;
import com.gohi.main.wxapi.vo.JsApi;
import com.gohi.main.wxapi.vo.Template;
import com.gohi.main.wxapi.vo.TemplateData;
import com.gohi.main.wxapi.vo.WxAccount;
import com.gohi.main.wxpay.api.WxPayUtil;

/**
 * 测试
 * 
 * @author Administrator
 * 
 */
public class TestAction extends BaseAction {
	Logger logger = Logger.getLogger(TestAction.class);
	// 系统
	private ISystemService systemService;
	// 商户
	private IStoreService storeService;
	// 用户
	private IUserService userService;

	// 测试发送微信的模板消息
	public void testmb() {
		Template t = new Template();
		Map<String, TemplateData> m = new HashMap<String, TemplateData>();
		m.put("product", new TemplateData("iPhone6 Plus"));

		m.put("first", new TemplateData("购买支付成功"));
		m.put("price", new TemplateData("7500"));
		m.put("time", new TemplateData("2014-04-15"));
		m.put("remark", new TemplateData("订单编号：10000000000000000000"));
		t.setData(m);
		t.setUrl("http://wx.gexinit.com/t!brand.do");
		t.setTemplate_id("rgO7rfELJWPSJTKuMlW-gv5wyIXFl14S_8705chFGzY");
		t.setTouser("olkcGj6Dh2z3NYcHqCFA7HvEuNzE");// 发送给谁
		String s = MsgXmlUtil.sendTemplateMsg(t, WxPayUtil.getAccount()
				.getAccess_token());

		System.err.println(s);
	}

	// 测试地区
	public void getare() {
		List<ShopgooArea> are = systemService.getAre();
		// System.err.println(are.get(0).getArea_name());
		AppJsonUtils.ptinrJson(systemService.getAre(), getRequest(),
				getResponse());
	}

	// 测试获取到微信首页轮播图片
	public void brand() {
		List<ShopgooArea> are = systemService.getAre();
		// System.err.println(are.get(0).getArea_name());
		AppJsonUtils.ptinrJson(systemService.getAllBrand(), getRequest(),
				getResponse());
	}

	// 测试所有的类型
	public void storeclass() {
		AppJsonUtils.ptinrJson(storeService.getStoreClass(), getRequest(),
				getResponse());
	}

	// ID查询商户类型
	public void classbyid() {
		AppJsonUtils.ptinrJson(
				storeService.getStoreClassByparentID(getRequest().getParameter(
						"id")), getRequest(), getResponse());
	}
	
	public void login() {
		System.err.println(userService.getByNames("yecheng"));
		ShopgooMember user =new ShopgooMember();
		user.setMember_name("admins");
		user.setPassword("123456");
		user.setEmail("1786210005@qq.com");
		user.setMobile("1786210005");
		user.setAvatar("hhhhhhhhhhhhhhhhhhh");
		user.setNickname("test");
		System.err.println("插入用户"+userService.regMember(user));
		
		
		
		AppJsonUtils.ptinrJson(userService.Login("yecheng", "111111"),
				getRequest(), getResponse());
	}
	
	public void message() {
		ShopgooMessage m =userService.queryMessage("1");
		System.err.println(m.getMobile());
	}
	
	public void index() {

	}

	public ISystemService getSystemService() {
		return systemService;
	}

	public void setSystemService(ISystemService systemService) {
		this.systemService = systemService;
	}

	public IStoreService getStoreService() {
		return storeService;
	}

	public void setStoreService(IStoreService storeService) {
		this.storeService = storeService;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

}
